var loadpage_timer;
$(document).on('scroll', function() {
	clearTimeout(loadpage_timer);
	var curdiv = $(window).scrollTop();
	if(document.getElementById("ainuoloadempty")){
		var curtop = $('#ainuoloadempty').offset().top - 650;
	}
	if(( curdiv > curtop) && !ainuo_forum_loading) {

		loadpage_timer = setTimeout(function() {
			if(document.getElementById("ainuoloadmore")){
				var ainuo_forum_ainuonextpage = getNodeNum();
			}
			if(ainuo_forum_ainuonextpage == 0){return;}
			var ainuo_forum_aloadnum = Math.ceil(ainuo_forum_ainuonextpage / ainuo_forum_aperpage) + 1;
			if (ainuo_forum_aloadnum >= (ainuo_forum_ainuomaxpage + 1)) {
				$('.loading').remove();
				document.getElementById("ainuoloadempty").innerHTML = ainuo_forum_empty;
				return;
			}
			ainuo_forum_loading = true;
			ainuo_forum_load(ainuo_forum_aloadnum);
		}, 100);
	
	}
});
function getNodeNum(){
	var newObj = document.getElementById("ainuoloadmore").childNodes;
	var nodeNum = 1;
	for(var i=0; i<newObj.length;i++){
		if(newObj[i].className=="plcnotfirst"){
			nodeNum++;
		}
	}
	return nodeNum;
}
	  
function ainuo_forum_load(id){
	$.ajax({
		type:'GET',
		url: ainuo_forum_url + id + '&inajax=1&mobile=2',
		dataType:'xml',
	})
	.success(function(s) {
		ainuo_forum_html = s.lastChild.firstChild.nodeValue;
		$('.ainuoloadmore').append(ainuo_forum_html);
		
		ainuo_forum_loading = false;
		$(".ainuolazyloadbg").lazyload({
			effect: "fadeIn",
			placeholder     : "template/qu_app/touch/style/lazy/lazy.png",
			threshold : 180,
			//failurelimit : 6,
			//container: $("#replylistnew"),
		});
		$(".ainuolazyload").lazyload({
			effect: "fadeIn",
			placeholder     : "template/qu_app/touch/style/lazy/lazy.png",
			threshold : 180,
			//failurelimit : 6,
			//container: $("#replylistnew"),
		});

	})
	
	.error(function() {
		document.getElementById("ainuoloadempty").innerHTML = ainuo_forum_emptyfail;
	});
}